import requests
import time


class FibonacciClient:
    def __init__(self, base_url="http://localhost:8000"):
        self.base_url = base_url

    def get_fibonacci(self, position: int, use_cache=True):
        """获取斐波那契数"""
        response = requests.post(
            f"{self.base_url}/fibonacci",
            json={
                "position": position,
                "use_cache": use_cache
            }
        )
        return response.json()


if __name__ == "__main__":
    client = FibonacciClient()

    # 测试带缓存的斐波那契计算
    print("测试带缓存的斐波那契计算:")
    start_time = time.time()
    result = client.get_fibonacci(35)
    print(f"结果: {result} | 耗时: {time.time() - start_time:.4f}秒")

    # 测试不带缓存的斐波那契计算
    print("\n测试不带缓存的斐波那契计算:")
    start_time = time.time()
    result = client.get_fibonacci(35, use_cache=False)
    print(f"结果: {result} | 耗时: {time.time() - start_time:.4f}秒")